package com.iknow.xmpp.smack.avatar;

import com.iknow.xmpp.smack.pep.PepSubManager;
import java.util.Arrays;
import java.util.List;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.pubsub.LeafNode;
import org.jivesoftware.smackx.pubsub.PayloadItem;

public class XmppAvatarRetriever
  implements AvatarRetriever
{
  private static String AVATARDATANODE = "urn:xmpp:avatar:data";
  private String mFrom;
  private String mId;
  private PepSubManager mPubsub;

  public XmppAvatarRetriever(Connection paramConnection, String paramString1, String paramString2)
  {
    this.mPubsub = new PepSubManager(paramConnection, paramString1);
    this.mFrom = paramString1;
    this.mId = paramString2;
  }

  public byte[] getAvatar()
  {
    byte[] arrayOfByte1;
    LeafNode localLeafNode;
    try
    {
      localLeafNode = this.mPubsub.getPEPNode(AVATARDATANODE);
      String[] arrayOfString = new String[1];
      arrayOfString[0] = this.mId;
      byte[] arrayOfByte2 = ((AvatarExtension)((PayloadItem)localLeafNode.getItems(Arrays.asList(arrayOfString)).get(0)).getPayload()).getData();
      arrayOfByte1 = arrayOfByte2;
      return arrayOfByte1;
    }
    catch (XMPPException localXMPPException)
    {
      arrayOfByte1 = null;
    }
  }
}